package org.example.Day10.huoche;

import org.example.Day10.bank.Account;

public class Ticket {
    private static int amount = 100;

    public synchronized void buyTicket(){
        if (amount > 0){
            System.out.println("购买成功");
            System.out.println( Thread.currentThread().getName()+"还剩北京到武汉的车票：" + (--amount));
        }else {
            System.out.println(Thread.currentThread().getName()+"票已经卖完了");
        }
    }

    public static class Buyer extends Thread{
        private final Ticket tickets;
        public Buyer(Ticket tickets,String name){
            super(name);
            this.tickets = tickets;
        }
        @Override
        public void run() {

            for (int i = 1; i <= 1; i++) {
                tickets.buyTicket();

            }

        }
    }
    public static void main(String[] args) {
        Ticket tickets = new Ticket();

        while(amount!=0) {
            for (int i = 1; i < 11; i++) {
                new Buyer(tickets, " 线程" + i).start();

            }
        }

    }
}
